package com.water.controller;

import com.water.dto.UserLoginDto;
import com.water.dto.UserRegisterDto;
import com.water.result.Result;
import com.water.service.UserService;
import com.water.vo.UserLoginVo;
import com.water.vo.UserUpVo;
import com.water.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: city_water
 * @description:
 * @author: lydms
 * @create: 2024-05-09 21:54
 **/

@RestController
@Slf4j
@RequestMapping("/user/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private UserService userService;


    //查看用户信息
    @GetMapping("/info")
    @ApiOperation("查看用户信息")
    public Result<UserVo> getUserInfo() {
        UserVo userVo =  userService.getUserInfo();
        return Result.success(userVo);
    }

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public Result<UserLoginVo> login(@RequestBody UserLoginDto userLoginDto) {

        log.info("登录手机号：{}", userLoginDto.getPhone());
       UserLoginVo userLoginVo = userService.login(userLoginDto);
        return Result.success(userLoginVo);
    }

    @PostMapping("/register")
    @ApiOperation("用户注册")
    //1'居民',2 '商业',3 '工业'
    public Result register(@RequestBody UserRegisterDto userRegisterDto) {
        log.info("注册手机号：{}", userRegisterDto.getName());
        userService.register(userRegisterDto);
        return Result.success();
    }

    /**
     * 修改信息
     */
    @PutMapping("/update")
    @ApiOperation("修改信息")
    public Result update(@RequestBody UserUpVo userUpVo){
        userService.update(userUpVo);
        return Result.success();
    }

    @PostMapping("/logout")
    @ApiOperation(value = "退出")
    public Result<String> logout() {
        return Result.success();
    }
}


